package com.spzx.product.api.factory;

import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.domain.vo.CategoryVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.List;

/**
 * ClassName: RemoteCategoryFallbackFactory
 * Package: com.spzx.product.api.factory
 * Description:
 * 类别管理服务降级处理
 *
 * @Author 咚咚小圆帽
 * @Create 2025/3/16 16:38
 * @Version 1.0
 */
@Component
public class RemoteCategoryFallbackFactory implements FallbackFactory<RemoteCategoryService> {
    @Override
    public RemoteCategoryService create(Throwable cause) {
        return new RemoteCategoryService() {
            @Override
            public R<List<CategoryVo>> getOneCategory(@RequestHeader(SecurityConstants.FROM_SOURCE) String source) {
                return R.fail("获取一级分类失败:" + cause.getMessage());
            }

            @Override
            public R<List<CategoryVo>> tree(String source) {
                return R.fail("获取全部分类失败:" + cause.getMessage());
            }
        };
    }
}
